package com.yxw.inactiondemo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by hp on 2015/11/27.
 */
public class Demo1 {
    public static void main(String[] args) throws Exception{
        ExecutorService executorService = Executors.newCachedThreadPool();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("i am is runnable");
            }
        };
        Callable callable = new Callable() {
            @Override
            public Object call() throws Exception {
                return "i am is callable";
            }
        };
        Future f1 = executorService.submit(runnable);
        Future f2 = executorService.submit(callable);
        System.out.println("runnable is completed"+f1.isDone());
        System.out.println("callable is completed"+f2.isDone());
        while(f1.isDone()){
            System.out.println("runnable completed");
            break;
        }
        while(f2.isDone()){
            System.out.println("callable completed"+f2.get());
            break;
        }
    }
}
